package org.nullauthor.allthings.mods;

import com.mojang.datafixers.types.Type;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.EnderChestBlockEntity;
import net.minecraft.datafixer.TypeReferences;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import org.nullauthor.allthings.Allthings;
import org.nullauthor.allthings.block.entity.EffectUpgradeEntity;

public class ModBlockEntityTypes {
//    public static <T extends BlockEntityType<?>> T register(String path, T blockEntityType) {
//        return Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(Allthings.MOD_ID, path), blockEntityType);
//    }

//    public static final BlockEntityType<EffectUpgradeEntity> EFFECT_UPGRADE_ENTITY = register(
//            "demo_block",
//
//            // 对于 1.21.2 之前的版本，请使用 BlockEntityType.Builder。
//            FabricBlockEntityTypeBuilder.create(EffectUpgradeEntity::new, ModBlocks.EFFECT_UPGRADE).build()
//    );

    private static <T extends BlockEntity> BlockEntityType<T> create(String id, BlockEntityType.Builder<T> builder) {
        Type<?> type = Util.getChoiceType(TypeReferences.BLOCK_ENTITY, id);
        return Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(Allthings.MOD_ID, id), builder.build(type));
    }

    public static final BlockEntityType<EffectUpgradeEntity> EFFECT_UPGRADE_ENTITY = create(
            "ender_chest", BlockEntityType.Builder.create(EffectUpgradeEntity::new, Blocks.ENDER_CHEST)
    );

    public static void initialize() {
    }
}
